package nodes.visitor;

import nodes.ConstNode;
import nodes.FuncNode;
import nodes.Node;
import nodes.ParamNode;

public class DisplayNodeVisitor implements NodeVisitor {
	
	private int level = 0;

	@Override
	public void visitConstNode(ConstNode<?> node) {		
		System.out.println(indent(level) + node.getValue());
	}

	@Override
	public void visitFuncNode(FuncNode<?> node) {	
		System.out.println(indent(level) + node.getName());
		
		level++;
		for(Node<?> child : node.getChildren())
			child.accept(this);

		level--;
	}

	@Override
	public void visitParamNode(ParamNode<?> node) {
		System.out.println(indent(level) + "p" + node.getParam());
	}
	
	private String indent(int indent) {
		String in = new String();
		for(int i = 0; i < indent; i++)
			in = in + " ";
		
		return in;
	}
}
